package testJdk.commonUse.dateAndCalendar.testCalendar;

import org.junit.Test;

import java.util.Calendar;

/**
 * @ClassName : learn_jdk.commonUse.date_and_calendar.testCalendar.TestCalendar
 * @Description : 类描述
 * Created by cyd on 2021-09-27 15:01:32
 */
public class TestCalendar {

    /**
     * Calendar获得时间的各个部分
     */
    @Test
    public void test01() {
        Calendar calendar = Calendar.getInstance();
        // 年
        int year = calendar.get(Calendar.YEAR);
        System.out.println("YEAR:" + year);
        // 月，要+1才是当前月
        int month = calendar.get(Calendar.MONTH) + 1;
        System.out.println("MONTH:" + month);
        // 日
        System.out.println("DAY_OF_YEAR:" + Calendar.DAY_OF_YEAR);
        System.out.println("DAY_OF_MONTH:" + Calendar.DAY_OF_MONTH);
        System.out.println("DAY_OF_WEEK:" + Calendar.DAY_OF_WEEK);

        // 小时，常用的有两种
        System.out.println("HOUR:" + calendar.get(Calendar.HOUR));
        System.out.println("HOUR_OF_DAY:" + calendar.get(Calendar.HOUR_OF_DAY));

        // 分钟
        System.out.println("MINUTE:" + calendar.get(Calendar.MINUTE));

        // 秒
        System.out.println("SECOND:" + calendar.get(Calendar.SECOND));

        // 毫秒
        System.out.println("MILLISECOND:" + calendar.get(Calendar.MILLISECOND));

    }
}
